package com.emergency.examine.controller;


import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.examine.domain.ExamStaff;
import com.emergency.examine.service.ExamStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by lijie on 2019/10/17.
 */
@RestController
@RequestMapping("/examstaff")
@Api(value = "考生类", tags = "记录考生信息")
public class ExamStaffController {
    @Autowired
    private ExamStaffService examStaffService;

    @ApiOperation(value = "考试成绩记录接口", notes = "记录考生考试信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "考生姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "num", value = "考生编号", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "team", value = "所属队", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "score", value = "考试成绩", required = true, paramType = "query", dataType = "Double")
    })
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public Result saveRecord(@RequestBody ExamStaff examStaff) {
        String id = examStaffService.saveRecord(examStaff);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    @ApiOperation(value = "考生成绩查询接口", notes = "查询考生成绩信息")
    @RequestMapping(value = "get/{staffId}", method = RequestMethod.GET)
    public Result get(@PathVariable("staffId") Long staffId) {
        ExamStaff examStaff = examStaffService.getInfo(staffId);
        return new Result(true, StatusCode.OK, "操作成功", examStaff);
    }

    @ApiOperation(value = "考生列表获取接口", notes = "考生列表")
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<ExamStaff> pageList = examStaffService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

    @ApiOperation(value = "删除考生信息接口", notes = "删除考生信息")
    @RequestMapping(value = "del/{staffId}", method = RequestMethod.POST)
    public Result delmsg(@PathVariable("staffId") Long staffId) {
        examStaffService.del(staffId);
        return new Result(true, StatusCode.OK, "删除成功");
    }

}
